package com.zzzy.common.vo;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.io.Serializable;
import java.util.List;

@Schema(description = "分页结果")
@Data
public class PageResult<T> implements Serializable {
    private static final long serialVersionUID = 6024634200398511653L;

    @Schema(description = "数据内容", requiredMode = Schema.RequiredMode.REQUIRED)
    private List<T> list;

    @Schema(description = "数据总量", requiredMode = Schema.RequiredMode.REQUIRED)
    private Long total;

    @Schema(description = "当前页数", requiredMode = Schema.RequiredMode.REQUIRED)
    private Long pageNum;

    @Schema(description = "每页数据量", requiredMode = Schema.RequiredMode.REQUIRED)
    private Long pageSize;

    @Schema(description = "总页数", requiredMode = Schema.RequiredMode.REQUIRED)
    private Long pages;

    @Schema(description = "是否有前一页", requiredMode = Schema.RequiredMode.REQUIRED)
    private boolean hasPreviousPage;

    @Schema(description = "是否有后一页", requiredMode = Schema.RequiredMode.REQUIRED)
    private boolean hasNextPage;

    public PageResult(IPage<T> page) {
        this.list = page.getRecords();
        this.total = page.getTotal();
        this.pageNum = page.getCurrent();
        this.pageSize = page.getSize();
        this.pages = page.getPages();
        this.hasPreviousPage = this.pageNum > 1;
        this.hasNextPage = this.pageNum < this.pages;
    }

    public PageResult() {
    }
}
